/**
 * @fileoverview
 * JavaScript helpers for demo and testing.
 * @author Hedger Wang (hedgerwang@gmail.com)
 */

function escapeHtml(str) {
  return str.
      replace(/&/g, '&amp;').
      replace(/>/g, '&gt;').
      replace(/</g, '&lt;').
      replace(/"/g, '&quot;');
}

function print() {
  try {
    var str = Array.prototype.slice.call(arguments, 0).join('');
    document.writeln('\n\n', escapeHtml(str));
  } catch(ex) {
    for (var i in ex) {
      document.writeln(i, ':', ex[i]);
    }
  }
}

function write() {
  try {
    var str = Array.prototype.slice.call(arguments, 0).join('');
    document.writeln('\n\n', str);
  } catch(ex) {
    for (var i in ex) {
      document.writeln(i, ':', ex[i]);
    }
  }
}